package group.hhsw.user_product.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import group.hhsw.common.model.UserProduct;
import group.hhsw.common.utils.Result;
import group.hhsw.user_product.service.UserProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hmj
 * @since 2022-02-24
 */
@RestController
@RequestMapping("/userproduct")
public class UserProductController {

    @Autowired
    private UserProductService userProductService;

    @PostMapping("/save")
    public Result saveUserProduct(@RequestBody UserProduct userProduct) {
        return Result.success(userProductService.save(userProduct));
    }

    @GetMapping("/getList/{account}")
    public Result getList(@PathVariable("account") String account) {
        List<UserProduct> list = userProductService.list(new LambdaQueryWrapper<UserProduct>()
                .eq(UserProduct::getAccount, account));
        return Result.success(list);
    }

    @GetMapping("/getUserPurchaseAmount")
    public Long getUserPurchaseAmount(@RequestParam("account") String account,
                                      @RequestParam("productId") String productId) {
        return userProductService.getUserPurchaseAmount(account,productId);
    }

}
